//
//  EPMCatergoryTableViewCell.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/4/28.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMCatergoryTableViewCell.h"

@interface EPMCatergoryTableViewCell()
///商品类别信息
@property (weak, nonatomic) IBOutlet UILabel *labTitle;
@property (weak, nonatomic) IBOutlet UIImageView *imgBig;
@property (weak, nonatomic) IBOutlet UIImageView *imgADFirst;
@property (weak, nonatomic) IBOutlet UIImageView *ImgADSecond;
@property (weak, nonatomic) IBOutlet UIImageView *imgADLast;
@property (weak, nonatomic) IBOutlet UILabel *labADDesFirst;
@property (weak, nonatomic) IBOutlet UILabel *labADDesSecond;
@property (weak, nonatomic) IBOutlet UILabel *labADDesLast;
@property (weak, nonatomic) IBOutlet UILabel *labADFirstPrice;
@property (weak, nonatomic) IBOutlet UILabel *labADFirstOldPrice;
@property (weak, nonatomic) IBOutlet UILabel *labADSecondPrice;
@property (weak, nonatomic) IBOutlet UILabel *labSecondOldPrice;
@property (weak, nonatomic) IBOutlet UILabel *labLastPrice;
@property (weak, nonatomic) IBOutlet UILabel *labLastOldPrice;
//跳转到超市
@property (weak,nonatomic)  UIControl* jumpControl;


@end
@implementation EPMCatergoryTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self setupUI];
    self.model = [EPMGoodsModel new];
    
}
- (void)setupUI{
    UIControl* jumpControl = [[UIControl alloc]init];
    self.jumpControl = jumpControl;
    [self.contentView addSubview:jumpControl];
//    [jumpControl sizeToFit];
    
    [jumpControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.contentView).offset(-10);
        make.centerY.equalTo(self.labTitle.mas_bottom);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    
    UILabel* label = [[UILabel alloc]init];
    label.text = @"更多";
    label.textColor = [UIColor darkGrayColor];
    [label sizeToFit];
    [jumpControl addSubview:label];
    
    
    
    UIImageView* imgView = [[UIImageView alloc]init];
    imgView.image = [UIImage imageNamed:@"icon_go"];
    [jumpControl addSubview:imgView];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.centerY.equalTo(jumpControl);
        make.width.mas_equalTo(5);
        make.height.mas_equalTo(10);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imgView);
        make.trailing.equalTo(imgView.mas_leading).offset(-7);
    }];
 
    //添加点击事件
    [jumpControl addTarget:self action:@selector(actionJumpToMarket:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - 点击事件 -
//跳转到闪电超市
- (void)actionJumpToMarket:(UIControl*)sender{
    if(self.CatergorySelectedBlock){
        self.CatergorySelectedBlock(self.activity);
    }
}

- (IBAction)actionAddGoods:(UIButton *)sender {
    UIImageView* imgIcon;
    self.model = self.activity.goods[sender.tag - 1];
    switch (sender.tag) {
        case 1:
            imgIcon = self.imgADFirst;
            
            break;
            case 2:
            imgIcon = self.ImgADSecond;
            break;
            case 3:
            imgIcon = self.imgADLast;
            
        default:
            break;
    }
    
    
    
    
    CGPoint imgIconCenter = imgIcon.center;
    
    CGPoint point = [ self convertPoint:imgIconCenter toView:kWindow];
    [[NSNotificationCenter defaultCenter]postNotificationName:EPMHomeIncreaseGoodNotification object:nil userInfo:@{                KIncreaseGoodPoint:[NSValue valueWithCGPoint:point],
                                                KIncreaseGoodImage:imgIcon.image,
                                                KIncreaseGoodsModel:self.model                                                           }] ;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 赋值 -

- (void)setActivity:(EPMActivityModel *)activity{
    _activity = activity;
    NSArray* goodList = activity.goods;
    EPMGoodsModel* firstModel = goodList[0];
    [self.imgADFirst sd_setImageWithURL:[NSURL URLWithString: firstModel.img]];
    self.labADDesFirst.text = firstModel.name;
    self.labADFirstPrice.text = firstModel.price;
    
    EPMGoodsModel* secondModel = goodList[1];
    [self.ImgADSecond sd_setImageWithURL:[NSURL URLWithString:secondModel.img]];
    self.labADDesSecond.text = secondModel.name;
    self.labADSecondPrice.text = secondModel.price;
    
    EPMGoodsModel* thirdModel = goodList[2];
    [self.imgADLast sd_setImageWithURL:[NSURL URLWithString:thirdModel.img]];
    self.labADDesLast.text = thirdModel.name;
    self.labADFirstOldPrice.text = thirdModel.price;
    
    
    self.labTitle.text = activity.name;
    [self.imgBig sd_setImageWithURL:[NSURL URLWithString:activity.img]];
}

@end
